namespace Collaboris.Saf.Actions.Moss.Tests.Generated
{
    using Engine.Report;

    using Entities;

    using Microsoft.SharePoint.Publishing;
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    using Navigation;

    using Saf.Tests;

    [TestClass]
    public class ShowInNavigationTest
    {
        #region Public Methods

        [TestMethod]
        public void ShowInNavigation_Test()
        {
            var showinnavigation = new TestAssistant<ShowInNavigation, NavigationSetting>(
                TestEnvironment.PublishingSite, "ShowInNavigationTestWeb", "BLANKINTERNET#0");

            using (showinnavigation)
            {
                MacroReport doReport = showinnavigation.DoMacro();

                PublishingWeb pubWeb = PublishingWeb.GetPublishingWeb(showinnavigation.TestWeb);
                foreach (PublishingWeb subWeb in pubWeb.GetPublishingWebs())
                {
                    if (showinnavigation.FirstEntity.ApplyToGlobalNav.Value)
                        Assert.AreEqual(this.EvalAction(showinnavigation.FirstEntity.SitesAction.Value), subWeb.IncludeInGlobalNavigation);

                    if (showinnavigation.FirstEntity.ApplyToCurrentNav.Value)
                        Assert.AreEqual(this.EvalAction(showinnavigation.FirstEntity.PagesAction.Value), subWeb.IncludeInCurrentNavigation);
                }

                foreach (PublishingPage subPage in pubWeb.GetPublishingPages())
                {
                    if (showinnavigation.FirstEntity.ApplyToCurrentNav.Value)
                        Assert.AreEqual(this.EvalAction(showinnavigation.FirstEntity.SitesAction.Value), subPage.IncludeInCurrentNavigation);

                    if (showinnavigation.FirstEntity.ApplyToGlobalNav.Value)
                        Assert.AreEqual(this.EvalAction(showinnavigation.FirstEntity.PagesAction.Value), subPage.IncludeInGlobalNavigation);
                }

                MacroReport unDoReport = showinnavigation.UndoMacro();

                pubWeb = PublishingWeb.GetPublishingWeb(showinnavigation.TestWeb);
                foreach (PublishingWeb subWeb in pubWeb.GetPublishingWebs())
                {
                    if (showinnavigation.FirstEntity.ApplyToGlobalNav.Value)
                        Assert.AreEqual(true, subWeb.IncludeInGlobalNavigation);

                    if (showinnavigation.FirstEntity.ApplyToCurrentNav.Value)
                        Assert.AreEqual(true, subWeb.IncludeInCurrentNavigation);
                }

                foreach (PublishingPage subPage in pubWeb.GetPublishingPages())
                {
                    if (showinnavigation.FirstEntity.ApplyToCurrentNav.Value)
                        Assert.AreEqual(true, subPage.IncludeInCurrentNavigation);

                    if (showinnavigation.FirstEntity.ApplyToGlobalNav.Value)
                        Assert.AreEqual(true, subPage.IncludeInGlobalNavigation);
                }
            }
        }

        private bool EvalAction(NavigationAction action)
        {
            if (action == NavigationAction.ExcludeFromNav)
                return false;
            if (action == NavigationAction.IncludeInNav)
                return true;

            return false;
        }

        #endregion
    }
}